# 登录页面封装
# 登录页面封装
from app_ui.lib.base.app_keywords import AppKeyWords
from app_ui.lib.common.common_function import *
from appium.webdriver.common.mobileby import MobileBy
from appium import webdriver


class LonginPage(AppKeyWords):
    # 登录页面元素

    username = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/input_login_username')
    password = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/input_login_pwd')
    login_button = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/btn_login')
    sava_password = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/btnSavePWD')
    login_auto = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/btnAutoLogin')
    user_agreement = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/cb_agreement')
    user_agree = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/btn_agree')
    # 进入工作台
    home_page = (MobileBy.ID, 'com.sensetime.iva.emerygency:id/iv_enforce')

    # 退出登录元素
    user_self = (By.XPATH, '//body/div/aside/div[3]/div[2]/div/span')
    out = (By.XPATH, '//a[text()="退出"]')

    # 登录操作
    def login(self, username, password):
        self.wait(1)
        self.input_value(self.username, text=username, context='用户名')
        self.input_value(self.password, password, context='密码')
        self.click(self.sava_password, context="记住用户名密码")
        self.click(self.login_auto, context="自动登录")
        self.click(self.login_button, context="登录")
        self.wait(3)
        # self.return_button()
        # self.wait(1)
        self.click(self.home_page, context="综合管理")
        self.wait(2)

    # 退出登录
    def login_out(self):
        '''
        退出登录操作
        :return:
        '''
        pass

    def login_by_yaml(self, data):
        element_operation(self, data)


if __name__ == '__main__':
    # 设置请求参数
    desired_caps = open_app_params('app_sit_82')
    # 打开首页
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    login = LonginPage(driver)
    # 打开app
    user = 'kobekq1'
    pw = 'kobe8888'
    login.login(user, pw)
    driver.quit()
